#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   FunctionalSafely.py
@Time    :   2025/01/06 13:31:28
@Author  :   YangLiang 
@Version :   1.0
@Contact :   YangLiang@chengtech.com
@License :   (C)Copyright 2022-2025
@Desc    :   None
'''

# here put the import lib
from pytest_assume.plugin import assume
 
import pytest
import logging
import time
from commDriver.modbus_plc import *
# from sympy import assuming
from commDriver.TS_CAN import *
import allure
import sys
import Set_up
from collections.abc import Iterable

sys.dont_write_bytecode = True
ReCornrfailrInit = 0x00


@allure.severity('critical')
class Test_FunctionalSafely(object): 
    
    '''故障注入函数'''
    def setVariantCodeDet(self, Driver, iStep, cmdString, profile=0):
        with allure.step(f'Step{iStep}:故障注入与消除'):
            logging.info("打开外部注入配置信息")
            try:
                Driver['CAN2'].sendAndread_CMD_Shell(0x115, f'profile {profile}', 100)
                respString = Driver['CAN2'].sendAndread_CMD_Shell(0x115, cmdString, 100)
                logging.info(f"命令执行成功: {respString}")
            except Exception as e:
                logging.error(f"命令执行失败: {e}")
                return iStep + 1, None

        return iStep + 1, respString

    
    def readRecornrFailr(self, Driver):
        try:
            Driver['CAN'].fush_q_buff()  # 清缓存  
            time.sleep(0.1)
            timeout = 2  # 设置超时时间为2秒
            start_time = time.time()  # 记录开始时间
            while True:
                ALl_data, _ = Driver['CAN'].read_frame()
                response_data = ALl_data[ALl_data['AIdentifier'] == 0x228]
                if not response_data.empty:
                    break
                # 检查是否超时
                if time.time() - start_time > timeout:
                    logging.error("命令执行超时，未收到响应")
                    return None
                time.sleep(0.02)    
            respData = response_data.iloc[0]['ADatas'][:32]
            ReCornrfailr = int((respData[8] & 0xC0) >> 6)
            logging.info(f"readRecornrFailr:{ReCornrfailr}")
            return ReCornrfailr
        except Exception as e:
            logging.error(f"读取RecornrFailr值失败: {e}")
            return None
    
    def stringToint(self, string):
        cleaned_string = ''.join(filter(str.isdigit, string.strip()))
        if cleaned_string: 
            return int(cleaned_string)
        logging.error("无法转换为空字符串")
        return None
    
    def executeTestStep(self, iStep, Driver, cmdString, expectedValue, isNotEqual=False):
        for i in range(4):
            iStep, respString = self.setVariantCodeDet(Driver, iStep, cmdString, i)
            value = self.stringToint(respString)
            if isNotEqual:
                with assume: 
                    assert value != expectedValue, logging.error(value)
            else:
                with assume: 
                    assert value == expectedValue, logging.error(value)
            time.sleep(0.05)
        return iStep

    @allure.severity('normal')
    @allure.description("Test Functional Safely FMCW Chirp Generation Lock Step TST_BB_02")
    def test_FMCW_Chirp_Generation_Lock_Step_TST_BB_02(self, action, Driver):
        iStep = 1
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x14, 0xFF, 0xFF, 0xFF], [0x54], 0, iStep, False)
        time.sleep(2)
        with allure.step(f'Step{iStep}:生成功能安全故障前RecornrFailr值 # {ReCornrfailrInit}'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == ReCornrfailrInit, logging.error(RecornrFailr)  
        with allure.step(f'Step{iStep}:生成功能安全故障前gSmHisFailMask值 # 00'):
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00)
        with allure.step(f'Step{iStep}:生成功能安全故障 # NA'):
            logging.info("生成功能安全故障")
            cmdString = 'cmd fsmErrInjection 130'
            iStep, _ = self.setVariantCodeDet(Driver, iStep, cmdString)
        with allure.step(f'Step{iStep}:生成功能安全故障后gSmHisFailMask值 # !=00'):    
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00, isNotEqual=True)
        with allure.step(f'Step{iStep}:生成功能安全故障后RecornrFailr值 # 03'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == 0x03, logging.error(RecornrFailr)
            
        # 掉电重启消除注入的故障
        iStep = Driver['CAN'].restartMRR_Power(Driver, iStep)
        
    @allure.severity('normal')
    @allure.description("Test Functional Safely baseband LBIST TST_BB_01")
    def test_baseband_LBIST_TST_BB_01(self,action,Driver):
        iStep = 1
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x14, 0xFF, 0xFF, 0xFF], [0x54], 0, iStep, False)
        time.sleep(2)
        with allure.step(f'Step{iStep}:生成功能安全故障前RecornrFailr值 # {ReCornrfailrInit}'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == ReCornrfailrInit, logging.error(RecornrFailr)  
        with allure.step(f'Step{iStep}:生成功能安全故障前gSmHisFailMask值 # 00'):
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00)
        with allure.step(f'Step{iStep}:生成功能安全故障 # NA'):
            logging.info("生成功能安全故障")
            cmdString = 'cmd fsmErrInjection 6'
            iStep, _ = self.setVariantCodeDet(Driver, iStep, cmdString)
        with allure.step(f'Step{iStep}:生成功能安全故障后gSmHisFailMask值 # !=00'):    
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00, isNotEqual=True)
        with allure.step(f'Step{iStep}:生成功能安全故障后RecornrFailr值 # 03'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == 0x03, logging.error(RecornrFailr)
            
        # 掉电重启消除注入的故障
        iStep = Driver['CAN'].restartMRR_Power(Driver, iStep)
        
        
    @allure.severity('normal')
    @allure.description("Test Functional Safely RF Power Detecto TST_TX_01")
    def test_RF_Power_Detecto_TST_TX_01(self,action,Driver):
        iStep = 1
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x14, 0xFF, 0xFF, 0xFF], [0x54], 0, iStep, False)
        time.sleep(2)
        with allure.step(f'Step{iStep}:生成功能安全故障前RecornrFailr值 # {ReCornrfailrInit}'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == ReCornrfailrInit, logging.error(RecornrFailr)  
        with allure.step(f'Step{iStep}:生成功能安全故障前gSmHisFailMask值 # 00'):
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00)
        with allure.step(f'Step{iStep}:生成功能安全故障 # NA'):
            logging.info("生成功能安全故障")
            cmdString = 'cmd fsmErrInjection 6'
            iStep, _ = self.setVariantCodeDet(Driver, iStep, cmdString)
        with allure.step(f'Step{iStep}:生成功能安全故障后gSmHisFailMask值 # !=00'):    
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00, isNotEqual=True)
        with allure.step(f'Step{iStep}:生成功能安全故障后RecornrFailr值 # 03'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == 0x03, logging.error(RecornrFailr)
            
        # 掉电重启消除注入的故障
        iStep = Driver['CAN'].restartMRR_Power(Driver, iStep)
        
    
    @allure.severity('normal')
    @allure.description("Test Functional Safely RF Power Detecto TST_TX_02")
    def test_RF_Power_Detecto_TST_TX_02(self,action,Driver):
        iStep = 1
        time.sleep(2)
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x14, 0xFF, 0xFF, 0xFF], [0x54], 0, iStep, False)
        time.sleep(2)
        with allure.step(f'Step{iStep}:生成功能安全故障前RecornrFailr值 # {ReCornrfailrInit}'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == ReCornrfailrInit, logging.error(RecornrFailr)  
        with allure.step(f'Step{iStep}:生成功能安全故障前gSmHisFailMask值 # 00'):
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00)
            
    
    @allure.severity('normal')
    @allure.description("Test Functional Safely SM12 TST_RX_01")
    def test_SM12_TST_RX_01(self,action,Driver):
        iStep = 1
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x14, 0xFF, 0xFF, 0xFF], [0x54], 0, iStep, False)
        time.sleep(2)
        with allure.step(f'Step{iStep}:生成功能安全故障前RecornrFailr值 # {ReCornrfailrInit}'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == ReCornrfailrInit, logging.error(RecornrFailr)  
        with allure.step(f'Step{iStep}:生成功能安全故障前gSmHisFailMask值 # 00'):
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00)
        with allure.step(f'Step{iStep}:生成功能安全故障 # NA'):
            logging.info("生成功能安全故障")
            cmdString = 'cmd fsmErrInjection 12'
            iStep, _ = self.setVariantCodeDet(Driver, iStep, cmdString)
        with allure.step(f'Step{iStep}:生成功能安全故障后gSmHisFailMask值 # !=00'):    
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00, isNotEqual=True)
        with allure.step(f'Step{iStep}:生成功能安全故障后RecornrFailr值 # 03'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == 0x03, logging.error(RecornrFailr)
            
        # 掉电重启消除注入的故障
        iStep = Driver['CAN'].restartMRR_Power(Driver, iStep)
    
    @allure.severity('normal')
    @allure.description("Test Functional Safely SM908 TST_RX_02 04 09 10")
    def test_SM908_TST_RX_02_04_09_10(self,action,Driver):
        iStep = 1
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x14, 0xFF, 0xFF, 0xFF], [0x54], 0, iStep, False)
        time.sleep(2)
        with allure.step(f'Step{iStep}:生成功能安全故障前RecornrFailr值 # {ReCornrfailrInit}'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == ReCornrfailrInit, logging.error(RecornrFailr)  
        with allure.step(f'Step{iStep}:生成功能安全故障前gSmHisFailMask值 # 00'):
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00)
            
    @allure.severity('normal')
    @allure.description("Test Functional Safely SM12 TST_RX_03")
    def test_SM11_TST_RX_03(self,action,Driver):
        iStep = 1
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x14, 0xFF, 0xFF, 0xFF], [0x54], 0, iStep, False)
        time.sleep(2)
        with allure.step(f'Step{iStep}:生成功能安全故障前RecornrFailr值 # {ReCornrfailrInit}'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == ReCornrfailrInit, logging.error(RecornrFailr)  
        with allure.step(f'Step{iStep}:生成功能安全故障前gSmHisFailMask值 # 00'):
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00)
        with allure.step(f'Step{iStep}:生成功能安全故障 # NA'):
            logging.info("生成功能安全故障")
            cmdString = 'cmd fsmErrInjection 11'
            iStep, _ = self.setVariantCodeDet(Driver, iStep, cmdString)
        with allure.step(f'Step{iStep}:生成功能安全故障后gSmHisFailMask值 # !=00'):    
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00, isNotEqual=True)
        with allure.step(f'Step{iStep}:生成功能安全故障后RecornrFailr值 # 03'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == 0x03, logging.error(RecornrFailr)
        # 掉电重启消除注入的故障
        iStep = Driver['CAN'].restartMRR_Power(Driver, iStep)
            
    @allure.severity('normal')
    @allure.description("Test Functional Safely SM8 TST_RX_03")
    def test_SM8_TST_RX_05(self,action,Driver):
        iStep = 1
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x14, 0xFF, 0xFF, 0xFF], [0x54], 0, iStep, False)
        time.sleep(2)
        with allure.step(f'Step{iStep}:生成功能安全故障前RecornrFailr值 # {ReCornrfailrInit}'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == ReCornrfailrInit, logging.error(RecornrFailr)  
        with allure.step(f'Step{iStep}:生成功能安全故障前gSmHisFailMask值 # 00'):
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00)
        with allure.step(f'Step{iStep}:生成功能安全故障 # NA'):
            logging.info("生成功能安全故障")
            cmdString = 'cmd fsmErrInjection 8'
            iStep, _ = self.setVariantCodeDet(Driver, iStep, cmdString)
        with allure.step(f'Step{iStep}:生成功能安全故障后gSmHisFailMask值 # !=00'):    
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00, isNotEqual=True)
        with allure.step(f'Step{iStep}:生成功能安全故障后RecornrFailr值 # 03'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == 0x03, logging.error(RecornrFailr)
            
        # 掉电重启消除注入的故障
        iStep = Driver['CAN'].restartMRR_Power(Driver, iStep)
            
    @allure.severity('normal')
    @allure.description("Test Functional Safely SM9 TST_RX_03")
    def test_SM9_TST_RX_06(self,action,Driver):
        iStep = 1
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x14, 0xFF, 0xFF, 0xFF], [0x54], 0, iStep, False)
        time.sleep(2)
        with allure.step(f'Step{iStep}:生成功能安全故障前RecornrFailr值 # {ReCornrfailrInit}'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == ReCornrfailrInit, logging.error(RecornrFailr)  
        with allure.step(f'Step{iStep}:生成功能安全故障前gSmHisFailMask值 # 00'):
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00)
        with allure.step(f'Step{iStep}:生成功能安全故障 # NA'):
            logging.info("生成功能安全故障")
            cmdString = 'cmd fsmErrInjection 9'
            iStep, _ = self.setVariantCodeDet(Driver, iStep, cmdString)
        with allure.step(f'Step{iStep}:生成功能安全故障后gSmHisFailMask值 # !=00'):    
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00, isNotEqual=True)
        with allure.step(f'Step{iStep}:生成功能安全故障后RecornrFailr值 # 03'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == 0x03, logging.error(RecornrFailr)
            
        # 掉电重启消除注入的故障
        iStep = Driver['CAN'].restartMRR_Power(Driver, iStep)
    
    @allure.severity('normal')
    @allure.description("Test Functional Safely SM10 TST_RX_03")
    def test_SM10_TST_RX_07(self,action,Driver):
        iStep = 1
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x14, 0xFF, 0xFF, 0xFF], [0x54], 0, iStep, False)
        time.sleep(2)
        with allure.step(f'Step{iStep}:生成功能安全故障前RecornrFailr值 # {ReCornrfailrInit}'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == ReCornrfailrInit, logging.error(RecornrFailr)  
        with allure.step(f'Step{iStep}:生成功能安全故障前gSmHisFailMask值 # 00'):
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00)
        with allure.step(f'Step{iStep}:生成功能安全故障 # NA'):
            logging.info("生成功能安全故障")
            cmdString = 'cmd fsmErrInjection 10'
            iStep, _ = self.setVariantCodeDet(Driver, iStep, cmdString)
        with allure.step(f'Step{iStep}:生成功能安全故障后gSmHisFailMask值 # !=00'):    
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00, isNotEqual=True)
        with allure.step(f'Step{iStep}:生成功能安全故障后RecornrFailr值 # 03'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == 0x03, logging.error(RecornrFailr)
            
        # 掉电重启消除注入的故障
        iStep = Driver['CAN'].restartMRR_Power(Driver, iStep)
            
    @allure.severity('normal')
    @allure.description("Test Functional Safely SM1 TST_PW_05")
    def test_SM1_TST_PW_05(self,action,Driver):
        iStep = 1
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x14, 0xFF, 0xFF, 0xFF], [0x54], 0, iStep, False)
        time.sleep(2)
        with allure.step(f'Step{iStep}:生成功能安全故障前RecornrFailr值 # {ReCornrfailrInit}'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == ReCornrfailrInit, logging.error(RecornrFailr)  
        with allure.step(f'Step{iStep}:生成功能安全故障前gSmHisFailMask值 # 00'):
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00)
            
    
    @allure.severity('normal')
    @allure.description("Test Functional Safely SM4 TST_PW_06")
    def test_SM4_TST_PW_06(self,action,Driver):
        iStep = 1
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x14, 0xFF, 0xFF, 0xFF], [0x54], 0, iStep, False)
        time.sleep(2)
        with allure.step(f'Step{iStep}:生成功能安全故障前RecornrFailr值 # {ReCornrfailrInit}'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == ReCornrfailrInit, logging.error(RecornrFailr)  
        with allure.step(f'Step{iStep}:生成功能安全故障前gSmHisFailMask值 # 00'):
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00)
        with allure.step(f'Step{iStep}:生成功能安全故障 # NA'):
            logging.info("生成功能安全故障")
            cmdString = 'cmd fsmErrInjection 4'
            iStep, _ = self.setVariantCodeDet(Driver, iStep, cmdString)
        with allure.step(f'Step{iStep}:生成功能安全故障后gSmHisFailMask值 # !=00'):    
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00, isNotEqual=True)
        with allure.step(f'Step{iStep}:生成功能安全故障后RecornrFailr值 # 03'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == 0x03, logging.error(RecornrFailr)
            
        # 掉电重启消除注入的故障
        iStep = Driver['CAN'].restartMRR_Power(Driver, iStep)
            
    @allure.severity('normal')
    @allure.description("Test Functional Safely SM5 TST_CLK_01")
    def test_SM5_TST_CLK_01(self,action,Driver):
        iStep = 1
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x14, 0xFF, 0xFF, 0xFF], [0x54], 0, iStep, False)
        time.sleep(2)
        with allure.step(f'Step{iStep}:生成功能安全故障前RecornrFailr值 # {ReCornrfailrInit}'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == ReCornrfailrInit, logging.error(RecornrFailr)  
        with allure.step(f'Step{iStep}:生成功能安全故障前gSmHisFailMask值 # 00'):
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00)
        with allure.step(f'Step{iStep}:生成功能安全故障 # NA'):
            logging.info("生成功能安全故障")
            cmdString = 'cmd fsmErrInjection 5'
            iStep, _ = self.setVariantCodeDet(Driver, iStep, cmdString)
        with allure.step(f'Step{iStep}:生成功能安全故障后gSmHisFailMask值 # !=00'):    
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00, isNotEqual=True)
        with allure.step(f'Step{iStep}:生成功能安全故障后RecornrFailr值 # 03'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == 0x03, logging.error(RecornrFailr)
            
        # 掉电重启消除注入的故障
        iStep = Driver['CAN'].restartMRR_Power(Driver, iStep)
            
    @allure.severity('normal')
    @allure.description("Test Functional Safely SM107 SSR_MEM_002")
    def test_SM107_SSR_MEM_002(self,action,Driver):
        iStep = 1
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x14, 0xFF, 0xFF, 0xFF], [0x54], 0, iStep, False)
        time.sleep(2)
        with allure.step(f'Step{iStep}:生成功能安全故障前RecornrFailr值 # {ReCornrfailrInit}'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == ReCornrfailrInit, logging.error(RecornrFailr)  
        with allure.step(f'Step{iStep}:生成功能安全故障前gSmHisFailMask值 # 00'):
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00)
        with allure.step(f'Step{iStep}:生成功能安全故障 # NA'):
            logging.info("生成功能安全故障")
            cmdString = 'cmd fsmErrInjection 107'
            iStep, _ = self.setVariantCodeDet(Driver, iStep, cmdString)
        with allure.step(f'Step{iStep}:生成功能安全故障后gSmHisFailMask值 # !=00'):    
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00, isNotEqual=True)
        with allure.step(f'Step{iStep}:生成功能安全故障后RecornrFailr值 # 03'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == 0x03, logging.error(RecornrFailr)
            
        # 掉电重启消除注入的故障
        iStep = Driver['CAN'].restartMRR_Power(Driver, iStep)
            
    @allure.severity('normal')
    @allure.description("Test Functional Safely SM109 SSR_MEM_006")
    def test_SM109_SSR_MEM_002(self,action,Driver):
        iStep = 1
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x14, 0xFF, 0xFF, 0xFF], [0x54], 0, iStep, False)
        time.sleep(2)
        with allure.step(f'Step{iStep}:生成功能安全故障前RecornrFailr值 # {ReCornrfailrInit}'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == ReCornrfailrInit, logging.error(RecornrFailr)  
        with allure.step(f'Step{iStep}:生成功能安全故障前gSmHisFailMask值 # 00'):
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00)
        with allure.step(f'Step{iStep}:生成功能安全故障 # NA'):
            logging.info("生成功能安全故障")
            cmdString = 'cmd fsmErrInjection 109'
            iStep, _ = self.setVariantCodeDet(Driver, iStep, cmdString)
        with allure.step(f'Step{iStep}:生成功能安全故障后gSmHisFailMask值 # !=00'):    
            cmdString = 'cmd get gSmHisFailMask 0 L 1'
            iStep = self.executeTestStep(iStep, Driver, cmdString, 0x00, isNotEqual=True)
        with allure.step(f'Step{iStep}:生成功能安全故障后RecornrFailr值 # 03'):
            RecornrFailr = self.readRecornrFailr(Driver)
            with assume: assert RecornrFailr == 0x03, logging.error(RecornrFailr)
            
        # 掉电重启消除注入的故障
        iStep = Driver['CAN'].restartMRR_Power(Driver, iStep)